package client_controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;

import client_gui.AnaliticSystemGUI;
import client_gui.MarketingEmployeeGUI;
import client_logic.CcrmClient;
import client_logic.dbHandler;
import entity.AddressingCustomer;
import entity.Boss;

public class AnaliticSystemController implements dbHandler {
	/**
	 * @class AnaliticSystemController allows communications between marketing employees and DB to extract customer information
	 * 
	 * @param AnaliticSystemGUI links to GUI.
	 * @param EmployeeLoginController links to check fields for employee authorization. 
	 * @param Boss is used as an instance, to send objects to DB and allow changes in the lists.
	 * @param MarketingEmployeeController links to check fields for employee authorization.
	 */

	private AnaliticSystemGUI asg;					
	private EmployeeLoginController elc;		
	private Boss b;								
	private MarketingEmployeeController mec;	

public AnaliticSystemController(AnaliticSystemGUI asg,EmployeeLoginController elc,MarketingEmployeeController mec){
	this.asg=asg;
	this.elc=elc;
	this.mec=mec;
	asg.getBtnBack().addActionListener(new BackLis());
	analyze();
	
}
public class BackLis implements ActionListener{
	public void actionPerformed(ActionEvent e) {
		asg.dispose();
		mec.getMeg().setVisible(true);
	}
}
public class LogoutLis implements ActionListener{
	public void actionPerformed(ActionEvent e) {
		setB(new Boss(elc.getEmp(),"logout","MarketingEmployeeController"));
		update();
	}
}
@Override
public void Add() {
	// TODO Auto-generated method stub
	
}
@Override
public void Search() {
	// TODO Auto-generated method stub
	
}
@Override
public String Delete() {
	// TODO Auto-generated method stub
	return null;
}
@Override
public void HandleMsg(Object msg) {
	this.setB((Boss) msg);
	if(b.getMsg().equals("ok")){
		asg.getLblOk().setVisible(true);
	}
		
	
}
@Override
public void update() {
	try {
		CcrmClient.inet.setCurrCon(this);
		CcrmClient.inet.sendToServer(b);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}	
}
public AnaliticSystemGUI getAsg() {
	return asg;
}
public void setAsg(AnaliticSystemGUI asg) {
	this.asg = asg;
}
public EmployeeLoginController getElc() {
	return elc;
}
public void setElc(EmployeeLoginController elc) {
	this.elc = elc;
}
public Boss getB() {
	return b;
}
public void setB(Boss b) {
	this.b = b;
}
public MarketingEmployeeController getMec() {
	return mec;
}
public void setMec(MarketingEmployeeController mec) {
	this.mec = mec;
}

public void analyze(){
	setB(new Boss(null,"analyze","AnaliticSystemController"));
	update();
}
}
